<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/applicationList' }">转正管理列表</el-breadcrumb-item>
                <el-breadcrumb-item>{{pageTitle}}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="table-form-box">
                <h3 class="h3">转正申请</h3>

                <table border="0" width="100%" cellpadding="0" cellspacing="1">
                    <tbody>
                        <tr class="tr-title">
                            <td colspan="6">基本信息</td>
                        </tr>
                        <tr>
                            <td align="right">单据编号:</td>
                            <td>{{formData.recordNo}}</td>
                            <td align="right">
                                <span class="color-ff2200">*</span>姓名:
                            </td>
                            <td>{{formData.correctUserName}}</td>
                        </tr>
                        <tr>
                            <td align="right">部门:</td>
                            <td>{{formData.departName}}</td>
                            <td align="right">岗位:</td>
                            <td>{{formData.jobRole}}</td>
                        </tr>
                        <tr>
                            <td align="right">
                                <span class="color-ff2200">*</span>入职日期:
                            </td>
                            <td>{{formData.onbordingTime|formatDate}}</td>

                            <td align="right">
                                <span class="color-ff2200">*</span>申请时间:
                            </td>
                            <td>{{formData.applyTime|formatDate}}</td>
                        </tr>
                        <tr>
                            <td align="right">
                                <span class="color-ff2200">*</span>申请转正日期:
                            </td>
                            <td>{{formData.epplyCorrentTime|formatDate}}</td>
                            <td align="right"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td align="right">备注:</td>
                            <td colspan="5">{{formData.remarks}}</td>
                        </tr>
                    </tbody>
                </table>

                <upload-files :files="fileList" :isShowDel="false" @fun="dealFiles" v-if="flag"></upload-files>
            </div>
        </div>
    </div>
</template>

<script>
import appMain from '../../../utils/app_main';
export default {
    name: 'applicationDetail',
    data() {
        return {
            pageTitle: '',
            formData: {
                applyTime: '', // 申请时间
                correctUserId: '', // 转正申请人id
                correctUserName: '', // 转正申请人
                departName: '', // 部门名称
                departId: '', // 部门编号
                epplyCorrentTime: '', // 申请转正时间
                jobRole: '', // 所属岗位
                jobRoleId: '', // 所属岗位ID
                onbordingTime: '', // 入职日期
                recordNo: '', // 单据编号
                remarks: '', // 备注信息
                status: '', // 流程状态
                statusTypeId: '', // 表单类型ID
                statusTypeName: '', // 表单类型名称

                uploadReturns: [
                    // 附件上传详情
                    {
                        fileName: '', // 文件名
                        fileType: '', // 文件类型名称
                        fileUrl: '', // 文件所在地址
                        ownerId: '', // 所关联的表主键id.即是该文件所属的表的主键
                        uploadUserId: '', // 文件上传人员ID
                        uploadUserName: '' //  文件上传人员名字
                    }
                ]
            },

            flag: false,
            isEdit: false,
            editId: '',
            dialogVisible: false,
            // 上传文件,选择的文件
            fileList: []
        };
    },
    created() {
        // 如果有id就是跳转过来修改的
        if (this.$route.query.id) {
            this.editId = this.$route.query.id;
            this.isEdit = true;
            this.getData(); // 获取要修改的数据
        } else {
            this.$router.push({
                //核心语句
                path: '/applicationList' //跳转的路径
            });
        }
    },
    methods: {
        getData() {
            appMain
                .correntFindById({}, this.editId)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.formData = res.data.data;
                        //获取人员档案附件
                        this.uploadFileInfoFindById(this.formData.id);
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //根据id查询附件
        uploadFileInfoFindById(id) {
            appMain
                .uploadFileInfoFindById({}, id)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.fileList = res.data.data;
                        this.flag = true;
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },

        // 选择员工
        showTreeDialog(tit) {
            console.log('showTreeDialog');
            this.searchDialogTit = tit;
            this.showSearch = true;
        },

        // 树组件搜索结果返回
        searchBack(data) {
            console.log(data.backData, 'searchTreeBack');
            this.formData.correctUserName = data.backData.name;
            this.formData.correctUserId = data.backData.id;
            this.formData.jobRole = data.backData.jobName;
            this.formData.jobRoleId = data.backData.jobId;
            this.formData.departName = data.backData.organizationName;
            this.formData.departId = data.backData.organizationId;
            this.showSearch = false;
        },
        closeTreeDialog(data) {
            this.showSearch = data.showDialog;
        },
        // 上传文件返回
        dealFiles(data) {
            this.fileList = data.backData;
            this.formData.uploadReturns = this.fileList;
        },
        submitForm(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    this.submit();
                    //this.resetForm('ruleForm');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        }
    },
    mounted() {
        this.pageTitle = this.$router.currentRoute.meta.title;
    },
    filters: {
        //时间过滤器
        formatDate: function(val) {
            let date = new Date(val);
            return appMain.formatDate(date, 'yyyy-MM-dd hh:mm:ss');
        }
    }
};
</script>

<style scoped>
.container {
    padding-bottom: 50px;
}
.handle-box {
    padding: 5px 50px;
    width: 100%;
    background-color: #fff;
    position: absolute;
    left: 0;
    bottom: 0px;
    border-bottom: 1px solid #ddd;
    border-top: 1px solid #ddd;
    z-index: 1;
}

.table {
    width: 100%;
    font-size: 14px;
}

.table-form-box table {
    background-color: #666;
}
.table-form-box .h3 {
    font-size: 22px;
    text-align: center;
    font-weight: normal;
    padding: 20px 0;
}
.table-form-box table .tr-title td {
    font-size: 14px;
    line-height: 40px;
}
.table-form-box table td,
.table-form-box table th {
    background-color: #fff;
    padding: 4px;
    min-height: 40px;
    font-size: 12px;
}
.color-ff2200 {
    color: #ff2200;
}
</style>
